using RxjhServer.DbClss;
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace RxjhServer
{
	public class 石头属性调整 : Form
	{
		private IContainer components = null;

		private Button button1;

		private ListView listView2;

		private ColumnHeader columnHeader11;

		private ColumnHeader columnHeader12;

		private ColumnHeader columnHeader13;

		private ColumnHeader columnHeader14;

		private TextBox textBox1;

		private Label label1;

		private Label label2;

		private TextBox textBox2;

		private Label label3;

		private TextBox textBox3;

		private Button button2;

		private ToolTip toolTip1;

		private Label label4;

		public 石头属性调整()
		{
			InitializeComponent();
		}

		private void 石头属性调整_Load(object sender, EventArgs e)
		{
			刷新();
		}

		private int 类型还原(string 类型)
		{
			int result = 0;
			switch (类型)
			{
			case "物品攻击力":
				result = 1;
				break;
			case "物品防御力":
				result = 2;
				break;
			case "生命力":
				result = 3;
				break;
			case "内功力":
				result = 4;
				break;
			case "命中率":
				result = 5;
				break;
			case "回避率":
				result = 6;
				break;
			case "武功攻击力":
				result = 7;
				break;
			case "升级成功率":
				result = 9;
				break;
			case "追加伤害值":
				result = 10;
				break;
			case "武功防御力":
				result = 11;
				break;
			case "获得金钱":
				result = 12;
				break;
			case "死亡损失经验减少":
				result = 13;
				break;
			case "经验获得":
				result = 15;
				break;
			}
			return result;
		}

		private string 类型命名(int 类型)
		{
			string result = "未知属性";
			switch (类型)
			{
			case 1:
				result = "物品攻击力";
				break;
			case 2:
				result = "物品防御力";
				break;
			case 3:
				result = "生命力";
				break;
			case 4:
				result = "内功力";
				break;
			case 5:
				result = "命中率";
				break;
			case 6:
				result = "回避率";
				break;
			case 7:
				result = "武功攻击力";
				break;
			case 9:
				result = "升级成功率";
				break;
			case 10:
				result = "追加伤害值";
				break;
			case 11:
				result = "武功防御力";
				break;
			case 12:
				result = "获得金钱";
				break;
			case 13:
				result = "死亡损失经验减少";
				break;
			case 15:
				result = "经验获得";
				break;
			}
			return result;
		}

		public void Set石头属性()
		{
			string sqlCommand = "SELECT * FROM 石头属性效果";
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, "PublicDb");
			if (dBToDataTable == null)
			{
				return;
			}
			if (dBToDataTable.Rows.Count == 0)
			{
				Form1.WriteLine(3, "加载石头数据出错----没有石头数据");
			}
			else
			{
				World.石头属性调整.Clear();
				for (int i = 0; i < dBToDataTable.Rows.Count; i++)
				{
					石头属性调整类 石头属性调整类 = new 石头属性调整类();
					石头属性调整类.类型 = (int)dBToDataTable.Rows[i]["FLD_TYPE"];
					石头属性调整类.数量 = (int)dBToDataTable.Rows[i]["FLD_VALUE"];
					石头属性调整类.加减 = (int)dBToDataTable.Rows[i]["FLD_增减"];
					World.石头属性调整.Add(i, 石头属性调整类);
				}
			}
			dBToDataTable.Dispose();
		}

		public void 刷新()
		{
			listView2.Items.Clear();
			string sqlCommand = "SELECT * FROM 石头属性效果";
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, "PublicDb");
			for (int i = 0; i < dBToDataTable.Rows.Count; i++)
			{
				ListViewItem listViewItem = new ListViewItem();
				listViewItem.SubItems.Clear();
				listViewItem.SubItems[0].Text = dBToDataTable.Rows[i]["ID"].ToString();
				string text = 类型命名(int.Parse(dBToDataTable.Rows[i]["FLD_TYPE"].ToString()));
				listViewItem.SubItems.Add(text);
				listViewItem.SubItems.Add(dBToDataTable.Rows[i]["FLD_VALUE"].ToString());
				listViewItem.SubItems.Add(dBToDataTable.Rows[i]["FLD_增减"].ToString());
				listView2.Items.Add(listViewItem);
			}
			dBToDataTable.Dispose();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			try
			{
				写数据(int.Parse(textBox1.Text), int.Parse(textBox2.Text), int.Parse(textBox3.Text));
				ListView.SelectedIndexCollection selectedIndices = listView2.SelectedIndices;
				listView2.Items[selectedIndices[0]].SubItems[1].Text = textBox1.Text;
				listView2.Items[selectedIndices[0]].SubItems[2].Text = textBox2.Text;
				listView2.Items[selectedIndices[0]].SubItems[3].Text = textBox3.Text;
				Set石头属性();
			}
			catch
			{
				MessageBox.Show("输入错误,请检查!");
			}
		}

		private void listView2_MouseClick(object sender, MouseEventArgs e)
		{
			ListView.SelectedIndexCollection selectedIndices = listView2.SelectedIndices;
			string text = 类型还原(listView2.Items[selectedIndices[0]].SubItems[1].Text).ToString();
			textBox1.Text = text;
			textBox2.Text = listView2.Items[selectedIndices[0]].SubItems[2].Text;
			textBox3.Text = listView2.Items[selectedIndices[0]].SubItems[3].Text;
		}

		private int 写数据(int type, int value, int 增减)
		{
			string sqlCommand = $"UPDATE 石头属性效果 SET FLD_增减={增减} WHERE FLD_TYPE={type} and FLD_VALUE={value}";
			try
			{
				int num = DBA.ExeSqlCommand(sqlCommand, "PublicDb");
				if (num == -1)
				{
					MessageBox.Show("写入表错误1,请检查|" + type.ToString() + "|" + value.ToString() + "|" + 增减.ToString());
					return -1;
				}
			}
			catch
			{
				MessageBox.Show("写入表错误2,请检查|" + type.ToString() + "|" + value.ToString() + "|" + 增减.ToString());
			}
			return -1;
		}

		private void button2_Click(object sender, EventArgs e)
		{
			string sqlCommand = $"SELECT FLD_VALUE FROM 石头属性效果 where FLD_VALUE={int.Parse(textBox2.Text)}";
			DataTable dBToDataTable = DBA.GetDBToDataTable(sqlCommand, "PublicDb");
			if (dBToDataTable.Rows.Count > 0)
			{
				MessageBox.Show("数量不能重复增加失败");
			}
			else
			{
				string sqlCommand2 = $"INSERT INTO 石头属性效果  (FLD_TYPE,FLD_VALUE, FLD_增减)VALUES({int.Parse(textBox1.Text)},{int.Parse(textBox2.Text)},{int.Parse(textBox3.Text)})";
				int num = DBA.ExeSqlCommand(sqlCommand2, "PublicDb");
				if (num == -1)
				{
					MessageBox.Show(string.Concat(new object[1]
					{
						"写入表错误1,请检查"
					}));
					return;
				}
				MessageBox.Show(string.Concat(new object[1]
				{
					"增加成功"
				}));
				Set石头属性();
				刷新();
			}
			dBToDataTable.Dispose();
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RxjhServer.石头属性调整));
			button1 = new System.Windows.Forms.Button();
			listView2 = new System.Windows.Forms.ListView();
			columnHeader11 = new System.Windows.Forms.ColumnHeader();
			columnHeader12 = new System.Windows.Forms.ColumnHeader();
			columnHeader13 = new System.Windows.Forms.ColumnHeader();
			columnHeader14 = new System.Windows.Forms.ColumnHeader();
			textBox1 = new System.Windows.Forms.TextBox();
			label1 = new System.Windows.Forms.Label();
			label2 = new System.Windows.Forms.Label();
			textBox2 = new System.Windows.Forms.TextBox();
			label3 = new System.Windows.Forms.Label();
			textBox3 = new System.Windows.Forms.TextBox();
			button2 = new System.Windows.Forms.Button();
			toolTip1 = new System.Windows.Forms.ToolTip(components);
			label4 = new System.Windows.Forms.Label();
			SuspendLayout();
			button1.Location = new System.Drawing.Point(321, 165);
			button1.Name = "button1";
			button1.Size = new System.Drawing.Size(111, 29);
			button1.TabIndex = 54;
			button1.Text = "修改立即生效";
			button1.UseVisualStyleBackColor = true;
			button1.Click += new System.EventHandler(button1_Click);
			listView2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[4]
			{
				columnHeader11,
				columnHeader12,
				columnHeader13,
				columnHeader14
			});
			listView2.FullRowSelect = true;
			listView2.GridLines = true;
			listView2.Location = new System.Drawing.Point(12, 12);
			listView2.Name = "listView2";
			listView2.Size = new System.Drawing.Size(275, 273);
			listView2.TabIndex = 55;
			listView2.UseCompatibleStateImageBehavior = false;
			listView2.View = System.Windows.Forms.View.Details;
			listView2.MouseClick += new System.Windows.Forms.MouseEventHandler(listView2_MouseClick);
			columnHeader11.Text = "id";
			columnHeader11.Width = 40;
			columnHeader12.Text = "石头类型";
			columnHeader12.Width = 84;
			columnHeader13.Text = "对应数";
			columnHeader13.Width = 68;
			columnHeader14.Text = "增减";
			columnHeader14.Width = 76;
			textBox1.Location = new System.Drawing.Point(354, 29);
			textBox1.Name = "textBox1";
			textBox1.Size = new System.Drawing.Size(66, 21);
			textBox1.TabIndex = 56;
			toolTip1.SetToolTip(textBox1, "对应石头属性类型");
			label1.AutoSize = true;
			label1.Location = new System.Drawing.Point(319, 32);
			label1.Name = "label1";
			label1.Size = new System.Drawing.Size(29, 12);
			label1.TabIndex = 57;
			label1.Text = "类型";
			label2.AutoSize = true;
			label2.Location = new System.Drawing.Point(319, 74);
			label2.Name = "label2";
			label2.Size = new System.Drawing.Size(29, 12);
			label2.TabIndex = 59;
			label2.Text = "数量";
			textBox2.Location = new System.Drawing.Point(354, 71);
			textBox2.Name = "textBox2";
			textBox2.Size = new System.Drawing.Size(66, 21);
			textBox2.TabIndex = 58;
			toolTip1.SetToolTip(textBox2, "对应石头属性数量");
			label3.AutoSize = true;
			label3.Location = new System.Drawing.Point(319, 119);
			label3.Name = "label3";
			label3.Size = new System.Drawing.Size(29, 12);
			label3.TabIndex = 61;
			label3.Text = "加减";
			textBox3.Location = new System.Drawing.Point(354, 116);
			textBox3.Name = "textBox3";
			textBox3.Size = new System.Drawing.Size(66, 21);
			textBox3.TabIndex = 60;
			toolTip1.SetToolTip(textBox3, "负数减反之加");
			button2.Location = new System.Drawing.Point(321, 200);
			button2.Name = "button2";
			button2.Size = new System.Drawing.Size(111, 29);
			button2.TabIndex = 62;
			button2.Text = "新增立即生效";
			button2.UseVisualStyleBackColor = true;
			button2.Click += new System.EventHandler(button2_Click);
			label4.AutoSize = true;
			label4.ForeColor = System.Drawing.Color.Red;
			label4.Location = new System.Drawing.Point(307, 260);
			label4.Name = "label4";
			label4.Size = new System.Drawing.Size(125, 12);
			label4.TabIndex = 63;
			label4.Text = "鼠标点放这里查看类型";
			toolTip1.SetToolTip(label4, "\"物品攻击力\":1\r\n\"物品防御力\":2\r\n\"生命力\":3\r\n\"内功力\":4                \r\n\"命中率\":5  \r\n\"回避率\":6\r\n\"武功攻击力\":7\r\n\"升级成功率\":9   \r\n\"追加伤害值\":10  \r\n\"武功防御力\":11           \r\n                  ");
			base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			base.ClientSize = new System.Drawing.Size(456, 292);
			base.Controls.Add(label4);
			base.Controls.Add(button2);
			base.Controls.Add(label3);
			base.Controls.Add(textBox3);
			base.Controls.Add(label2);
			base.Controls.Add(textBox2);
			base.Controls.Add(label1);
			base.Controls.Add(textBox1);
			base.Controls.Add(listView2);
			base.Controls.Add(button1);
			base.Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon");
			base.MaximizeBox = false;
			base.MinimizeBox = false;
			base.Name = "石头属性调整";
			Text = "石头属性调整";
			base.Load += new System.EventHandler(石头属性调整_Load);
			ResumeLayout(false);
			PerformLayout();
		}
	}
}
